<?php

class user extends Controller
{
    public function index()
    {
		require APP . 'views/site_templates/header.php';
        require APP . 'views/user/index.php';
        require APP . 'views/site_templates/footer.php';
    }
	
    public function signup() {
		$result = 0;
    	if($_POST['user_signup_submit']) {
    		//print "<pre>" . print_r($_POST , true ) . "<pre>"; exit;
    		$result = $this->model->userSignUp();
    		header('location: ' . URL . 'user?result='.$result);
    	}
    }
    
    public function login() {
    	
    	if (isset($_POST["user_login_submit"])) {
            $userInfo = $this->model->userLogin($_POST["email"],$_POST["password"]);
            if(!empty($userInfo)) {
            	$_SESSION['user'] = array();
            	$_SESSION['user']['email'] = $userInfo->email;
            	$_SESSION['user']['first_name'] = $userInfo->first_name;
            	$_SESSION['user']['last_name'] = $userInfo->last_name;
            	$_SESSION['user']['user_id'] = $userInfo->user_id;
            }
        }
    	
    	if(!empty($_SESSION['user'])) {
    		header('location: ' . URL);
    	} else {
    		require APP . 'views/site_templates/header.php';
        	require APP . 'views/user/login.php';
        	require APP . 'views/site_templates/footer.php';
    	}
    }
    
	public function logout() {
		$_SESSION['user'] = array();
    	header('location: ' . URL);
    }

   

}
